package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.entity.ExamItem;
import com.woniu.entity.SurgeryItem;
import com.woniu.mapper.SurgeryItemMapper;
import com.woniu.service.SurgeryItemService;
import com.woniu.utils.ResponseEnum;
import com.woniu.utils.ResponseUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SurgeryItemServiceImpl implements SurgeryItemService {
    @Resource
    private SurgeryItemMapper surgeryItemMapper;
    @Override
    public ResponseUtil selectAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SurgeryItem> surgeryItems = surgeryItemMapper.selectAll();
        PageInfo pageInfo = new PageInfo(surgeryItems);
        return surgeryItems != null ?ResponseUtil.get(ResponseEnum.OK,pageInfo)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil updateSurgery(Integer id) {
        int rows = surgeryItemMapper.updateSurgery(id);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil insertSelective(SurgeryItem record) {
        int rows = surgeryItemMapper.insertSelective(record);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK, record)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil updateByPrimaryKeySelective(SurgeryItem record) {
        int rows = surgeryItemMapper.updateByPrimaryKeySelective(record);
        return rows == 1
                ? ResponseUtil.get(ResponseEnum.OK)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil selectByCondition(String itemName, String roomName, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<SurgeryItem> surgeryItemList = surgeryItemMapper.selectByCondition(itemName,roomName,status);
        PageInfo pageInfo = new PageInfo(surgeryItemList);
        return surgeryItemList!=null ? ResponseUtil.get(ResponseEnum.OK,pageInfo)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    @Override
    public ResponseUtil findAll() {
        List<SurgeryItem> surgeryItems = surgeryItemMapper.findAll();
        return surgeryItems != null ?ResponseUtil.get(ResponseEnum.OK,surgeryItems)
                :ResponseUtil.get(ResponseEnum.FAIL);
    }
}
